package components;


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;


import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint;


public class ImageFactory{
	
	private static ImageFactory inst = new ImageFactory();

	private ImageFactory(){}
	
	public static ImageFactory getInstance(){
		return inst;
	}
	 
	
	public Image createImage(Resources res, int resourceID) throws FileNotFoundException{
		Image img = null;
		String resource = res.getString(resourceID);
		//if(determineImageType(resource) == Image.TYPE_BITMAP){
			img = this.createBitmapImage(res,resourceID);
		//}
		//else if this.isSVG(resource)
		if(img != null){
			img.setName(resource);
			img.setPosX(0);
			img.setPosY(0);
			img.setPaint(new Paint());
			
		}
		return img;
		
	}
	
	public Image createImage(String path) throws FileNotFoundException{
		Image img = null;
		String resource = path;
		if(determineImageType(resource) == Image.TYPE_BITMAP){
			img = this.createBitmapImage(resource);
		}
		//else if this.isSVG(resource)
		if(img != null)
			img.setName(resource.substring(resource.indexOf(".")));
		return img;
		
	}
	
	private Image createBitmapImage(String resource) {
		// TODO Auto-generated method stub
		return null;
	}

	private int determineImageType(String resource) {
		if(resource.endsWith("jpg") || resource.endsWith(".png"))
			return Image.TYPE_BITMAP;
		return -1;
	}

	public Image createBitmapImage(Resources res, int id) throws FileNotFoundException {
		Bitmap mBitmap = BitmapFactory.decodeResource(res, id);
		Image img = new Image(mBitmap);
		return img;
	}
	 

}
